// 深度优先遍历
var deepTraversal = function(obj, result){
    if(!obj.children){
        result.push(obj.id);
        return;
    }else{
        result.push(obj.id);
        var childs = obj.children;
        for(var i = 0; i < childs.length; i++){
            deepTraversal(childs[i],result);
        }
    }
}
var result = [];
deepTraversal(obj,result);
console.log(result);
// 广度优先遍历
var widthTraversal = function(obj,result){
    var stack = [];
    stack.push(obj);
    while(stack.length){
        var item = stack.shift();
        result.push(item.id);
        var childs = item.children;
        if(childs){
            for(var i = 0; i < childs.length; i++){
                stack.push(childs[i]);
            }
        }
    }
}
var result1 = [];
widthTraversal(obj,result1);
console.log(result1);
